//------------------------------------------------------------------------------
// Copyright (c) 2008 www.dnaide.com
// Licensed under the MIT (MIT-LICENSE.txt)
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Configuration;
using DNAide.Web;

namespace DNAide.Configuration
{
	public class ScriptAideReplacementRuleConfig : ConfigurationElement
	{
		internal object _lock = new object();
		private Regex _patternMatchExpressionRegex;

		public Regex PatternMatchExpressionRegex
		{
			get
			{
				if (_patternMatchExpressionRegex == null)
				{
					lock (_lock)
					{
						if (_patternMatchExpressionRegex == null)
						{
							if (DNAideConfigurationSettings.Web.ScriptAide.RegexCompilationMode == RegexCompilationType.Compiled)
							{
								_patternMatchExpressionRegex = new Regex(DNAide.Web.UrlAide.Resolve(MatchExpression), RegexOptions.IgnoreCase | RegexOptions.Compiled);
							}
							else
							{
								_patternMatchExpressionRegex = new Regex(DNAide.Web.UrlAide.Resolve(MatchExpression), RegexOptions.IgnoreCase);
							}
						}
					}
				}
				return _patternMatchExpressionRegex;
			}
		}

		[ConfigurationProperty("matchExpression", IsRequired = true)]
		public String MatchExpression
		{
			get
			{
				return (string)this["matchExpression"];
			}
			set
			{
				this["matchExpression"] = value;
			}
		}


		[ConfigurationProperty("replaceExpression", IsRequired = true)]
		public String ReplaceExpression
		{
			get
			{
				return (string)this["replaceExpression"];
			}
			set
			{
				this["replaceExpression"] = value;
			}
		}

	}
}
